package com.tenebrous.jestic.service.framwork.meber.organ;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tenebrous.jestic.entity.framwork.meber.organ.OrgUserCerti;
import com.tenebrous.jestic.mapper.idao.framwork.meber.organ.OrgUserCertiMapper;
import com.tenebrous.jestic.service.SuperService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class OrgUserCertieService extends SuperService<OrgUserCerti> {

    @Autowired
    private OrgUserCertiMapper mapper;

    @Override
    @Autowired
    protected void setSuperMapper() {
        super.setSuperMapper(this.mapper);
    }

    public List<OrgUserCerti> queryCertieList(String userid) {
        return this.mapper.selectCertieListByUserid(userid);
    }

    public PageInfo queryPagingList(Integer pageIndex, Integer pageSize, String userid) {
        return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> this.mapper.selectCertieListByUserid(userid));
    }

    @Transactional
    public int deleteByIds(String[] ids) {
        int i = 0;
        for (String id : ids) {
            if (StringUtils.isNotBlank(id)) {
                i += this.mapper.deleteByPrimaryKey(id);
            }
        }
        return i;
    }
}
